#include "Avalon/IOTests/MockClientChannel.hpp"
#include "Avalon/IO/PipedReader.hpp"
#include "Avalon/IO/PipedWriter.hpp"
#include "Avalon/IOTests/MockClientConnection.hpp"

using namespace Avalon;
using namespace Avalon::IO;
using namespace Avalon::IO::Tests;
using namespace Avalon::IO::Tests::Details;
using namespace boost;

MockClientChannel::MockClientChannel(MockServerConnection* server) {
  m_reader.reset(new PipedReader());
  m_serverWriter.reset(new PipedWriter(m_reader.get()));
  m_serverReader.reset(new PipedReader());
  m_writer.reset(new PipedWriter(m_serverReader.get()));
  m_connection.reset(new MockClientConnection(server, this, m_serverReader,
    m_reader));
}

MockClientChannel::~MockClientChannel() {}

Connection& MockClientChannel::GetConnection() {
  return *m_connection;
}

Reader& MockClientChannel::GetReader() {
  return *m_reader;
}

Writer& MockClientChannel::GetWriter() {
  return *m_writer;
}

Channel* MockClientChannel::CreateServerChannel() {
  return new ServerToClientChannel(m_connection, m_serverReader,
    m_serverWriter);
}
